<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
	<title></title>
	<link rel="stylesheet" href="Public/Admin/css.css" />
	<link rel="stylesheet" type="text/css" href="Public/bootstrap.css"/>
	<link rel="stylesheet" href="__PUBLIC__/Css/common.css" />
	 <script type="text/javascript" src="Public/uploadify/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="Public/uploadify/jquery.uploadify.min.js"></script>
    <link rel="stylesheet" type="text/css" href="Public/uploadify/uploadify.css">
	<script type="text/javascript" src='__ROOT__/Public/Ueditor/ueditor.config.js'></script>
	<script type="text/javascript" src='__ROOT__/Public/Ueditor/ueditor.all.min.js'></script>
	<link rel="stylesheet" type="text/css" href="Public/goods.js"/>
	  <!--载入百度编辑器-->
	    	<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.config.js"></script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/ueditor.all.min.js"> </script>
    		<script type="text/javascript" charset="utf-8" src="Public/ueditor1_4_3/lang/zh-cn/zh-cn.js"></script>
	<!--<script type="text/javascript" src='__PUBLIC__/Js/goods.js'></script>-->
	
	<style type="text/css">
		/*去掉uploadify上传按钮的边框*/
	    .uploadify-button {
	        background-color: transparent;
	        border: none;
	        padding: 0;
	    }
	    .uploadify:hover .uploadify-button {
	        background-color: transparent;
    	}
    	.hide{
    		display: none;
    	}
    	body{
    		margin-bottom: 100px;
    	}
    	.cha{cursor: pointer;}
	</style> 
	<script type="text/javascript">
		$(function(){
			//就是我们在分类里面有个come=cid
			$('[name=cid]').change(function(){
				
				//这个tid就是我们数据表里的tid；
				var tid = $('option:selected').attr('tid');
				$.ajax({
					type:"post",
					url:"<?php echo U('getTypeAttr')?>",
					data:{id : tid},
					dataType:'json',
					success:function(phpData){
						//规格(可选)
						var spec = '';
						//属性（不可选）
						var attr = '';
						$.each(phpData, function(k,v) {    
							//规格
							if(v.class == 1){
								spec += '<tr class="info">' +
								'<td>'+v.taname+'</td>' +
								'<td>' +
									'<select name="spec['+v.taid+'][value][]" id=""><option value="">请选择</option>';
										$.each(v.tavalue, function(kk,vv) {    
											 spec += '<option value="'+vv+'">'+vv+'</option>';                                                      
										});
									spec += '</select></td><td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" id="" /></td>' +
										'<td><span class="btn btn-success add-spec">增加规格</span></td></tr>';
							
							}else{//属性
								attr += '<tr class="info">' + 
											'<td>'+v.taname+'</td>' + 
											'<td>' + 
											'<select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
												
												$.each(v.tavalue, function(kk,vv) {    
													 attr += '<option value="'+vv+'">'+vv+'</option>';                                                      
												});
												
								attr += '</select></td></tr>';
							}                                                          
						});
						
						//插入属性
						$('#attr').html(attr);
						$('#spec').html(spec);
					}
				});
			})
	
	
			//点击添加规格
			$('.add-spec').live('click',function(){
				//找到父级的tr
				var parentsTr = $(this).parents('tr');
				//把父级的tr克隆复制
				var cloneTr = parentsTr.clone();
				cloneTr.find('.add-spec').removeClass('add-spec btn-success').addClass('remove-spec btn-danger').html('删除规格');
				//插入下一行
				parentsTr.after(cloneTr);
			})
			//删除规格
			$('.remove-spec').live('click',function(){
				$(this).parents('tr').remove();
			})
			//删除图片
			$(".cha").live('click',function(){
				$(this).parent().remove();
			})
		})
	</script>
</head>
<body>
	<div class="container-fluid">
	<div class="row-fluid">
	<div class="span12">

	<form action="" method='post'>
		<fieldset>
			<legend>編輯商品</legend>
			<table class='table table-bordered table-hover'>
				<thead>
					<tr>
						<th colspan="2" class="btn btn-primary">基本信息</th>
					</tr>
				</thead>
				<tbody>
					<tr class="info">
						<td>所属分类</td>
						<td>
							<select name="cid">
								<option value="0">-请选择-</option>
								  <?php foreach ($cateData as $v){?>
									<option value="<?php echo $v['cid']?>" tid="<?php echo $v['type_tid']?>"<?php if($v['cid']==$oldData['category_cid']){?>
                 selected 
               <?php }?>><?php echo $v['_name']?></option>
								 <?php }?>
								
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>所属品牌</td>
						<td>
							<select name="bid">
								<option value="0">-请选择-</option>
								<?php foreach ($branddata as $v){?>
									<option value="<?php echo $v['bid']?>"<?php if($v['bid']==$oldData['brand_bid']){?>
                 selected 
               <?php }?>><?php echo $v['bname']?></option>
								<?php }?>
							</select>
						</td>
					</tr>
					<tr class="info">
						<td>商品名称</td>
						<td>
							<input type="text" name='gname'value="<?php echo $oldData['gname']?>"/>
						</td>
					</tr>
					
					
					
					<tr class="info">
						<td>庫存</td>
						<td>
							<input type="text" name='ginventory'value="<?php echo $oldData['ginventory']?>"/>
						</td>
					</tr>
					
					
					
					
					<tr class="info">
						<td>单位</td>
						<td>
							<input type="text" name='gunit' value='件'/>
						</td>
					</tr>
					<tr class="info">
						<td>市价场</td>
						<td>
							<input type="text" name='gmarket'value="<?php echo $oldData['gmarket']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>商城价</td>
						<td>
							<input type="text" name='gsale'value="<?php echo $oldData['gsale']?>"/>
						</td>
					</tr>
					<tr class="info">
						<td>点击次数</td>
						<td>
							<input type="text" name='gclick'value="<?php echo $oldData['gclick']?>"/>
						</td>
					</tr>
				</tbody>
			</table>

			<p class="btn btn-primary">商品属性</p>
			<table class="table table-bordered table-hover" id='attr' class="info">
				<?php foreach ($Ge as $v){?>
				   <?php if($v['class']==0){?>
                
				    <tr class="info">
				    	<td><?php echo $v['taname']?></td>
				    	<td>
				    		
				    		<select name="gtvalue[<?php echo $v['gaid']?>]">
				    			<?php foreach ($v['tavalue'] as $b){?>
				    			<option <?php if($v['gtvalue']==$b){?>
                 selected
               <?php }?> value="<?php echo $b?>"><?php echo $b?></option>
				    			<?php }?>
				    		</select>
				    		
				    	</td>
				    </tr>
				    
               <?php }?>
				<?php }?>
			</table>
			<p class="btn btn-primary">商品规格</p>
			<table class="table table-bordered table-hover" id='spec'>
				<?php foreach ($Ge as $v){?>
				   <?php if($v['class']==1){?>
                
				    <tr class="info">
				    	<td><?php echo $v['taname']?></td>
				    	<td>
				    		<select name="gtvalue[<?php echo $v['gaid']?>]">
				    			<?php foreach ($v['tavalue'] as $b){?>
				    			<option <?php if($v['gtvalue']==$b){?>
                 selected
               <?php }?> value="<?php echo $b?>"><?php echo $b?></option>
				    			<?php }?>
				    		</select>
				    	</td>
				    	<td>附加价格：<input type="text" value="<?php echo $v['gadded']?>" name="extra[<?php echo $v['gaid']?>][extra][]"/></td>
				    	<td><span class="btn btn-success add-spec">增加规格</span></td>
				    </tr>
				    
               <?php }?>
				<?php }?>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">列表图</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="f" type="file" multiple="true">
    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
    <script type="text/javascript">
        $(function() {
            $('#f').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
                'uploader' : '<?php echo U('upload')?>',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 10,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    //转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li><img style='width:80px;height:80px;' src='"+imageUrl+"'/> <input type='hidden' name='gpics' value='"+data.path+"'/></li>";
                    $("#g_f ul").prepend(li);
                }
            });
        });
    </script>
    <div id="g_f">
    	<ul>
    	<li>
    		<input type="hidden" name='gpic' value="<?php echo $oldData['gpics']?>"/>
    		<img style='width:200px;height:120px' src="<?php echo $oldData['gpics']?>" alt="" />
    		<span class="cha">X</span>
    	</li>
    	</ul>
    </div>
					</td>
					<td id='pic-list'></td>
				</tr>
			</table>

			<table class='table table-bordered'>
				<tr>
					<th colspan="3" class="btn btn-primary">商品图册</th>
				</tr>
				<tr class="info">
					<td>上传图片</td>
					<td>
						<input id="a" type="file" multiple="true">
    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
    <script type="text/javascript">
        $(function() {
            $('#a').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '<?php echo __PUBLIC__?>/uploadify/uploadify.swf',
                'uploader' : '<?php echo U('upload')?>',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 10,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
                    //转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li><img style='width:80px;height:80px;'src='"+imageUrl+"'/><input type='hidden' name='gpic[]' value='"+data.path+"'/></li>";
                    $("#g ul").prepend(li);
                }
            });
        });
    </script>
		<div id="g">
			<ul>
				<?php foreach ($GparData['gpic'] as $v){?>
				<li>
					<img style='width:200px;height:120px' src="<?php echo $v?>" alt="" />
					<span class="cha">X</span>
					<input type="hidden"  name='gpic[]' value="<?php echo $v?>"/>
				</li>
			    <?php }?>
				</ul>
			</div>			
					</td>
					<td id='photo-list'></td>
				</tr>
			</table>
			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">商品详细</th>
				</tr>
				<tr class=" " style="width: 100%;">
					<td>
						<!--调用百度编辑器-->
			<script id="editor" type="text/plain" style="width:100%;height:200px;" name="content">
			<?php echo $GparData['gpar']?>
			</script>
		    <script>
		        var ue = UE.getEditor('editor');
		    </script>
						
					</td>
				</tr>
			</table>

			<table class='table'>
				<tr class="next_show">
					<th class="btn btn-primary">售后服务</th>
				</tr>
				<tr class="hide info">
					<td>
						<textarea name="service" id="service"></textarea>
					</td>
				</tr>
			</table>
			<input type="hidden" name='gid' value="<?php echo $oldData['gid']?>"/>
			<input type="submit" value="确认编辑" class="btn btn-primary btn-block btn-large" />
		</fieldset>
	</form>

	</div>
	</div>
	</div>
</body>
</html>